﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="doanhnghiep-add.aspx.cs" Inherits="VQWEB.administrator.huongnghiep.doanhnghiep.doanhnghiep_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <form id="frmObjects" action="" method="post">
        <div id="col8" class="col-md-8"></div>
        <div id="col4" class="col-md-4"></div>
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/huongnghiep/doanhnghiep/handler";
        var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';

        $(document).ready(function () {
            $.get(url_ashx, { view_doanhnghiep: "view_doanhnghiep", Id: GetId() }, function (data) {
                var parse = $.parseJSON(data);
                var chuyennganh = parse.chuyennganh;
                var array_chuyennganh;
                if (CheckAtionInPath("add")) {
                    array_chuyennganh = array_checkbox(chuyennganh);
                    loadform(0, "", "", "", "", "", "", "", 0, false, false, array_chuyennganh);
                }
                else if (CheckAtionInPath("edit")) {
                    var doanhnghiep = parse.doanhnghiep;
                    var chuyennganh = parse.chuyennganh;
                    var array_chuyennganh = array_checkbox(chuyennganh);
                    loadform(doanhnghiep.id, doanhnghiep.ten, doanhnghiep.gioithieu, doanhnghiep.logo, doanhnghiep.diachi, doanhnghiep.website, doanhnghiep.email, doanhnghiep.dienthoai, doanhnghiep.hit, doanhnghiep.ishome, doanhnghiep.active, array_chuyennganh);
                }
            });
        });

        function loadform(id, ten, gioithieu, logo, diachi, website, email, dienthoai, hit, ishome, active, array_chuyennganh) {
            $.jqoteload(url_input, function (tmpl) {
                $("#col4").multiple("groupcheckbox", null, array_chuyennganh, "Chuyên ngành:", tmpl.input_tpl);
                $("#col8").single("hidden", "doanhnghiep_id", id, null, null, tmpl.input_tpl);
                $("#col8").single("text", "doanhnghiep_ten", ten, "Tên Doanh nghiệp:", null, tmpl.input_tpl);
                $("#col8").single("editor", "doanhnghiep_gioithieu", gioithieu, "Giới thiệu:", null, tmpl.input_tpl);
                $("#col8").single("text", "doanhnghiep_logo", logo, "Logo:", null, tmpl.input_tpl);
                $("#col8").single("text", "doanhnghiep_diachi", diachi, "Địa chỉ:", null, tmpl.input_tpl);
                $("#col8").single("text", "doanhnghiep_website", website, "Website:", null, tmpl.input_tpl);
                $("#col8").single("text", "doanhnghiep_email", email, "Email:", null, tmpl.input_tpl);
                $("#col8").single("text", "doanhnghiep_dienthoai", dienthoai, "Điện thoại:", null, tmpl.input_tpl);
                $("#col8").single("text", "doanhnghiep_hit", hit, "Lượt xem:", 0, tmpl.input_tpl);
                $("#col8").single("checkbox", "doanhnghiep_ishome", true, "Trang chủ", ishome, tmpl.input_tpl);
                $("#col8").single("checkbox", "doanhnghiep_active", true, "Kích hoạt", active, tmpl.input_tpl);
                tinymce.init({ selector: 'textarea#tinymce' });
                $("#frmObjects").validate({
                    rules: { doanhnghiep_ten: { required: true }},
                    messages: { doanhnghiep_ten: { required: null } }
                });
                $("input[name='doanhnghiep_dienthoai']").mask("99999999");
            });

        }

        $(document).on("click", "#btnCancel", function () {
            window.location = "/admin/huongnghiep/doanhnghiep/list";
        });
        $(document).on("click", "#btnSave", function () {
            if ($("#frmObjects").valid()) {
                var value = tinymce.get('tinymce').getContent();
                $("textarea[name='doanhnghiep_gioithieu']").val(value);
                var arr = $("#frmObjects").serializeObject();
                $.post(url_ashx, { add_doanhnghiep: window.escape(arr) }, function (data) {
                    alert(data);
                    window.location = "/admin/huongnghiep/doanhnghiep/list";
                });
            }
        });
    </script>
</asp:Content>
